﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ApplicationDAL;

namespace Architecture.Implementation.Console.EntityFramework
{
    class MeasurePerformance : IMeasurePerformance
    {

        public void InitEnvironment()
        {
            this.Warmup();
        }

        public void Warmup()
        {
            using (ApplicationServiceContext ctx = new ApplicationServiceContext())
            {
                try
                {
                    var result = ctx.ExternalLinks.Take(5);
                   
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            }
        }

        public void SingleCallQuery()
        {
            ApplicationDAL.Models.ExternalLink link = new ApplicationDAL.Models.ExternalLink()
            {
                Summary = "Single Add measure",
                Title= "Single Add measure"
            };

            using (ApplicationServiceContext ctx = new ApplicationServiceContext())
            {
                try
                {
                    ctx.ExternalLinks.Add(link);
                    var countChanges = ctx.SaveChanges();
                }
                catch(Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            }
            
        }
    }
}
